package com.example.japinhands.ui.screen

import android.util.Log
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.japinhands.JApplication.Companion.showToast
import com.example.japinhands.JapViewModel
import com.example.japinhands.data.Sentence

@Composable
fun ManageSentenceScreen(
    viewModel: JapViewModel
) {
    val mContext = LocalContext.current
    val tag = "ManageSentenceScreen"
    val sentences = remember {
        mutableStateListOf<Sentence>()
    }
    LaunchedEffect(Unit) {
        viewModel.getAllSentences {
            it?.let { sentences.addAll(it) }
        }
    }
    LazyColumn {
        sentences.forEach {
            item {
                Text(
                    text = it.content,
                    modifier = Modifier
                        .clickable {
                            showToast("You clicked id: ${it.id}")
                            Log.d(tag, "Clicked ${it.id}: ${it.content}")
                        }
                        .padding(8.dp)
                        .fillMaxWidth(),
                    fontSize = 25.sp
                )
            }
        }
    }
}